<template>
  <el-dialog title="" :visible.sync="onekeydialog" width="80%" class="task-content" append-to-body @close="close1">
    <div class="refine_dtcreate">
      <h2 class="titleblue">{{title}}</h2>
      <div class="contant">
        <div class="tit-cont">
          <div class="tit-div">
            <div class="blue-div">
              <img src="@/assets/taskCreateBlue.png" v-if="task.createTime"/>
              <img src="@/assets/taskCreateG.png" v-else>
            </div>
            <p>{{task.createTime}}</p>
          </div>
          <div class="line-div">
            <p class="blue-line" v-if="task.sendTime"></p>
            <p class="grey-line" v-else></p>
          </div>
          <div class="tit-div margin25">
            <div class="blue-div">
              <img src="@/assets/taskUnitB.png" v-if="task.sendTime"/>
              <img src="@/assets/taskUnitG.png" v-else>
            </div>
            <p>{{task.sendTime}}</p>
          </div>
          <div class="line-div">
            <p class="blue-line" v-if="task.finishTime"></p>
            <p class="grey-line" v-else></p>
          </div>
          <div class="tit-div margin25">
            <div class="blue-div">
              <img src="@/assets/taskedB.png" v-if="task.finishTime">
              <img src="@/assets/taskedG.png" v-else>
            </div>
            <p>{{task.finishTime}}</p>
          </div>
        </div>
        <!--任务填写项-->
        <el-form ref="form" :disabled="formDisabled" :model="task" label-width="110px">
          <el-row>
            <el-col :span="10">
              <el-form-item label="任务名称" prop="name" :rules="[{ required: true, message: '任务名称不能为空'}]">
                <el-input v-model="task.name" placeholder="" class="select-width-220"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="14">
              <el-form-item label="任务编号">
                <el-input v-model="task.taskNo" placeholder="自动生成" disabled class="select-width-220"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="任务类型" :rules="[{ required: true, message: '任务类型不能为空'}]">
                <el-row>
                  <el-col :span="20">
                    <div v-for="(element, index) in task.taskTypeFlows" class="unit-wrap clear">
                      <el-select v-model="element.type1" placeholder="" class="select-width-150"
                                 :disabled="formDisabled"
                                 @change="typeChange($event, index)">
                        <el-option v-for="item in taskType" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                      <div class="fl" style="margin-right: 10px;">
                        <el-select v-model="element.type2" placeholder="" class="w98" :disabled="formDisabled"
                                   @change="typeChange2($event, index)">
                          <el-option v-for="item in element.taskType2" :key="item.id" :label="item.name"
                                     :value="item.id">
                          </el-option>
                        </el-select>
                      </div>
                      <div class="fl" style="margin-right: 10px;">
                        <el-select v-model="element.type3" placeholder="" class="w98" :disabled="formDisabled">
                          <el-option v-for="item in element.taskType3" :key="item.id" :label="item.name"
                                     :value="item.id">
                          </el-option>
                        </el-select>
                      </div>
                      <i class="el-icon-circle-close" @click="task.taskTypeFlows.splice(index,1)"
                         v-if="index !=0 && !formDisabled"></i>
                    </div>
                  </el-col>
                  <el-col :span="4">
                    <el-button type="primary" class="blue-button" @click="addTaskTypesRow()" v-if='!formDisabled'>添加任务类型
                    </el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="任务对象">
              <el-col :span="12">
                <div v-for="(item, index) in taskObject">
                  <el-input clearable v-model="item.taskObject" placeholder=""
                            style="width: calc(100% - 30px);margin-bottom: 10px;"></el-input>
                  <i class="el-icon-circle-close" @click="taskObject.splice(index,1)" style="font-size: 20px;"
                     v-if="index !=0 && !formDisabled"></i>
                </div>
              </el-col>
              <el-col :span="4">
                <el-button type="primary" class="blue-button" @click="addTaskObjectRow()" v-if='!formDisabled'>添加任务对象
                </el-button>
              </el-col>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="任务创建人">
                <el-input v-model="task.fullname" class="select-width-220 bgcolor-ccc" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="14">
              <el-form-item label="任务对象类型">
                <el-select v-model="task.object1" placeholder="" class="select-width-150" @change="objectChange($event)">
                  <el-option v-for="item in taskObjectType" :key="item.id" :label="item.taskname" :value="item.id">
                  </el-option>
                </el-select>
                <el-select v-model="task.object2" clearable v-if='objectOptionSon.length!=0' placeholder=""
                           class="select-width-150"
                           @change='changeObjectType($event)'>
                  <el-option v-for="item in objectOptionSon" :key="item.id" :label="item.taskname" :value="item.id">
                  </el-option>
                </el-select>
                <el-select v-model="task.object3" clearable v-if='shipTypeThree.length!=0' placeholder=""
                           class="select-width-150">
                  <el-option v-for="item in shipTypeThree" :key="item.id" :label="item.taskname" :value="item.id">
                  </el-option>
                </el-select>
<!--                <el-input v-model="task.objectName" v-if="objectInputShow" placeholder=""-->
<!--                          class="select-width-220"></el-input>-->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="!formDisabled">
            <el-col :span="24">
              <el-form-item label="值班人员" :rules="[{ required: true, message: '值班人员不能为空'}]">
                <el-select clearable v-model="currentOrg" class="select-width-300" placeholder="机构选择" @change="changeOrg">
                  <el-option v-for="item in organization" :key="item.id" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
                <el-select clearable v-model="currentSubOrg" style="margin-right:10px;" class="select-width-300"
                           placeholder="部门选择" @change="searchGroup">
                  <el-option v-for="item in subOrgList" :key="item.id" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="">
                <el-select clearable v-model="dutyId" style="margin-right:10px;" class="select-width-300"
                           placeholder="人员选择">
                  <el-option v-for="item in subPeopleList" :key="item.id" :label="item.fullname" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="formDisabled">
            <el-col :span="24">
              <el-form-item label="值班人员" :rules="[{ required: true, message: '值班人员不能为空'}]">
                <el-input type="text" :rows="4" v-model="task.dutyFullname" placeholder="" class="select-width-300"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="任务概要" :rules="[{ required: true, message: '任务概要不能为空'}]">
                <el-input type="textarea" :rows="4" v-model="task.summary" placeholder="" class="height-300"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!--附件添加-->
          <el-row v-if='!formDisabled'>
            <el-form-item label="参考附件">
              <el-upload class="upload-demo" ref="upload" :action="$config.FILE_UPLOAD_URL" :data='uploadobj'
                         :headers="headers" :limit="9" accept='.png,.jpg,.jpeg,.docx,.pdf,.xlsx,.xls,.txt' multiple
                         :before-upload='beforeupload' :on-success='uploadSuccess' :on-remove="uploadRemove"
                         :file-list="fileList" :on-exceed="handleExceed">
                <el-button size="small" type="primary">上传</el-button>
                <div slot="tip" class="el-upload__tip"></div>
              </el-upload>
            </el-form-item>
          </el-row>
          <!--附件回显-->
          <el-row v-if='type!="add"'>
            <el-col>
              <el-form-item label='参考附件'>
                <div class="annex-width">
                  <a class="annex-div" v-for='(item,index) in bgImg1' target='_blank' :href="item" download="">
                    <img :src="item"/>
                  </a>
                  <a class="annex-div file-div" v-for='(item,index) in fileImg1' target='_blank'
                     :href="item" download="item">
                    <div>{{item.substring(item.lastIndexOf('task/') + 5, item.length)}}</div>
                  </a>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <!--任务派发新建修改-->
            <el-col :span="20">
              <el-form-item label="任务派发" class="unit-wrap clear">
                <template v-for="(element, index) in lhpf">
                  <el-select v-model="element.organiza" clearable style='padding-bottom: 20px;' class="select-width-220"
                             placeholder="" :disabled="formDisabled"
                             @change="manageChange($event, index)">
                    <el-option v-for="item in organization" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                  <el-select class="select-width-220" clearable v-model="element.organiza2" :disabled="formDisabled"
                             placeholder="" @change="disChange($event, index)">
                    <el-option v-for="item in element.organizas" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                  <i class="el-icon-circle-close" style="float: unset;" @click="lhpf.splice(index,1)"
                     v-if="index !=0 && !formDisabled"></i>
                  <el-button type="primary" @click="addPfdw(index)" v-if="!formDisabled && index == 0">联合派发</el-button>
                  <el-row style="margin-bottom: 10px;">
                    <el-col :span="20">
                      <div v-for="(ele, index) in element.enforceLaw" class="unit-wrap clear">
                        <el-select v-model="ele.person" clearable placeholder="执法人员推荐" class="w33"
                                   :disabled="formDisabled">
                          <el-option v-for="item in ele.lawPeople" :key="item.id" :label="item.fullname"
                                     :value="item.id">
                          </el-option>
                        </el-select>
                        <el-select v-model="ele.carrier" clearable placeholder="执法船艇推荐" class="w33"
                                   :disabled="formDisabled">
                          <el-option v-for="item in ele.lawShip" :key="item.id" :label="item.name"
                                     :value="item.id">
                          </el-option>
                        </el-select>
                        <el-select v-model="ele.vehicle" clearable placeholder="执法车辆推荐" class="w33"
                                   :disabled="formDisabled">
                          <el-option v-for="item in ele.lawCar" :key="item.id" :label="item.name"
                                     :value="item.id">
                          </el-option>
                        </el-select>
                        <el-select v-model="ele.tool" clearable placeholder="执法工具推荐" class="w33"
                                   :disabled="formDisabled">
                          <el-option v-for="item in ele.lawTool" :key="item.id" :label="item.name"
                                     :value="item.id">
                          </el-option>
                        </el-select>
                        <i class="el-icon-circle-close" @click="element.enforceLaw.splice(index,1)"
                           v-if="index !=0 && !formDisabled"></i>
                      </div>
                    </el-col>
                    <el-col :span="4">
                      <el-button type="primary" class="blue-button" @click="addUnitRow(index)" v-if='!formDisabled'>
                        添加执行单元
                      </el-button>
                    </el-col>
                  </el-row>
                </template>
              </el-form-item>
            </el-col>
          </el-row>
          <!--专项-->
          <el-row>
            <el-col :span="16">
              <el-form-item label="专项">
                <el-col :span="4">
                  <el-checkbox v-model="task.special">是</el-checkbox>
                </el-col>
                <el-col :span="20" class="special-cont">
                  <el-checkbox-group v-model="specialList" v-show="task.special">
                    <el-checkbox v-for="item in plans" :label="item.id" :key="item.id" :disabled="formDisabled">
                      {{item.name}}
                    </el-checkbox>
                  </el-checkbox-group>
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="任务等级" :rules="[{ required: true, message: '任务等级不能为空'}]">
                <el-select v-model="task.grade" placeholder="" class="select-width-220">
                  <el-option v-for="item in gradeOptions" :key="item.id" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="任务地点" class="select-width-220">
                <el-input v-model="task.location" placeholder="" class="select-width-220"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="任务完成期限">
                <el-date-picker v-model="task.deadline" type="datetime" value-format='yyyy-MM-dd HH:mm:ss'
                                placeholder=""
                                :picker-options="pickerOptions1">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!--任务反馈详情项-->
          <el-form-item label="缺陷项" class="inlinebox" v-if='xiangqing'>
            <div v-for="(item,index) in form.defectItem" style='margin-bottom:10px;'>
              <el-input v-model="item.defectitem" disabled placeholder="" class="select-width-220 clear"></el-input>

              <label style="float: none;">滞留缺陷</label>
              <el-radio-group style="width: 300px;margin-left:10px" v-model="item.retention" disabled>
                <el-radio :label='1'>是</el-radio>
                <el-radio :label='0'>否</el-radio>
              </el-radio-group>
            </div>
          </el-form-item>
          <el-row v-if='xiangqing'>
            <el-col :span="10">
              <el-form-item label="检查数量">
                <el-input disabled v-model="form.shipCount" placeholder=""
                          class="select-width-220"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="巡航里程(海里)">
                <el-input disabled v-model="form.cruise" placeholder=""
                          class="select-width-220"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if='xiangqing'>
            <el-col :span="6">
              <el-form-item label="缺陷数量">
                <el-input disabled v-model="form.defectCount" placeholder=""></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="滞留缺陷数量">
                <el-input disabled v-model="form.retentionCount" placeholder=""></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="已整改缺陷数量">
                <el-input disabled v-model="form.rectifyCount" placeholder=""></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="执行情况" v-if='xiangqing'>
              <el-input type="textarea" v-model="form.implementation" class="width700" disabled></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="处理措施" v-if='xiangqing'>
              <el-col :span='24'>
                <el-checkbox-group v-model="form.finalResult.measureCheck">
                  <el-row>
                    <el-col :span='8'>
                      <el-checkbox disabled label="立案调查"></el-checkbox>
                    </el-col>
                    <el-col :span='8'>
                      <el-checkbox disabled label="行政处罚"></el-checkbox>
                    </el-col>
                    <el-col :span='8'>
                      <el-checkbox disabled label="滞留"></el-checkbox>
                    </el-col>
                    <el-col :span='8'>
                      <el-checkbox disabled label="违法记分"></el-checkbox>
                    </el-col>
                    <el-col :span='8'>
                      <el-checkbox disabled label="警示教育"></el-checkbox>
                    </el-col>
                  </el-row>
                </el-checkbox-group>
              </el-col>
              <el-col :span='24' style="margin-top:10px;">
                <el-input type="textarea" disabled :rows="4" v-model="form.finalResult.textarea"
                          placeholder=""></el-input>
              </el-col>
              <!--<div class="punish" v-for='(item,index) in punishment' :key='index'>
                <el-checkbox :checked='item.choose' :disabled='xiangqing'>{{item.name}}</el-checkbox>
                <el-select v-model='item.value' style="width:120px;margin:0px 10px" class="select-width-100"
                           :disabled='xiangqing' v-if='item.choose&&item.pms.length!=0'>
                  <el-option v-for="it in item.pms" :key="it.d_id" :label="it.name" :value="it.name">
                  </el-option>
                </el-select>
              </div>
              <el-col :span='24' v-if="form.task_final">
                <el-input type="textarea" :rows="4" v-model="form.task_final" placeholder=""></el-input>
              </el-col>-->
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="备注" v-if='xiangqing'>
              <el-input type="textarea" v-model="form.remark" class="width700" disabled></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col v-if='formDisabled&&xiangqing&&task.url'>
              <el-form-item label='任务附件'>
                <div class="annex-width">
                  <a class="annex-div" v-for='(item,index) in bgImg1' target='_blank' :href="item" download="">
                    <img :src="item"/>
                  </a>
                  <a class="annex-div file-div" v-for='(item,index) in fileImg1' target='_blank'
                     :href="item" download="item">
                    <div>{{item.substring(item.lastIndexOf('task/') + 5, item.length)}}</div>
                  </a>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="视频" class="inlinebox" v-if="xiangqing&&video.length!=0">
            <div class="annex-width">
              <video class="annex-div" :src="video" v-for="(video, index) in video" :key='index'
                     @click="videoPlay(index)"></video>
            </div>
          </el-form-item>
          <!--抄送-->
          <el-row class="checkgroup" :gutter="10" v-if='!formDisabled'>
            <el-form-item label="抄送">
              <el-col :span="4" v-if="Zero.length!=0">
                <div class="grid-content groupli copylist">
                  <p>局领导</p>
                  <el-checkbox v-model="checkZero" @change="nodeChange('zeroTree', 'Zero')" class="allchck">全选
                  </el-checkbox>
                  <el-tree
                    :data="Zero"
                    show-checkbox
                    node-key="id"
                    @check-change="treeChange('zeroTree')"
                    ref="zeroTree"
                    highlight-current
                    :props="defaultProps"
                    accordion>
                  </el-tree>
                </div>
              </el-col>
              <el-col :span="4" v-if="One.length!=0">
                <div class="grid-content groupli copylist">
                  <p>业务部门</p>
                  <el-checkbox v-model="checkOne" @change="nodeChange('oneTree', 'One')" class="allchck">全选
                  </el-checkbox>
                  <el-tree
                    :data="One"
                    show-checkbox
                    node-key="id"
                    @check-change="treeChange('oneTree')"
                    ref="oneTree"
                    highlight-current
                    :props="defaultProps"
                    accordion>
                  </el-tree>
                </div>
              </el-col>
              <el-col :span="4" v-if="Two.length!=0">
                <div class="grid-content groupli copylist">
                  <p>行政部门</p>
                  <el-checkbox v-model="checkTwo" @change="nodeChange('twoTree', 'Two')" class="allchck">全选
                  </el-checkbox>
                  <el-tree
                    :data="Two"
                    show-checkbox
                    node-key="id"
                    @check-change="treeChange('twoTree')"
                    ref="twoTree"
                    highlight-current
                    :props="defaultProps"
                    accordion>
                  </el-tree>
                </div>
              </el-col>
              <el-col :span="4" v-if="Three.length!=0">
                <div class="grid-content groupli copylist">
                  <p>海事处</p>
                  <el-checkbox v-model="checkThree" @change="nodeChange('threeTree', 'Three')" class="allchck">全选
                  </el-checkbox>
                  <el-tree
                    :data="Three"
                    show-checkbox
                    node-key="id"
                    @check-change="treeChange('threeTree')"
                    ref="threeTree"
                    highlight-current
                    :props="defaultProps"
                    accordion>
                  </el-tree>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="grid-content groupli copylist">
                  <div>自定义抄送
                    <div class="copybtn fr" @click="cusClick">自定义</div>
                  </div>
                  <el-checkbox v-model="checkCustom" @change="nodeChange('customTree', 'Custom')" class="allchck">全选
                  </el-checkbox>
                  <el-tree
                    :data="Custom"
                    show-checkbox
                    node-key="id"
                    @check-change="treeChange('customTree')"
                    ref="customTree"
                    highlight-current
                    :props="defaultProps"
                    accordion>
                  </el-tree>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="grid-content groupli copylist">
                  <p>抄送人数共计{{copylistP.length}}人</p>
                  <ul v-for="(item,index) in copylistP" :key='index'>
                    <li>{{item.label}}</li>
                  </ul>
                </div>
              </el-col>
            </el-form-item>
          </el-row>
          <el-row v-if='formDisabled&&copylista!=""' class="csdiv">
            <el-form-item label="抄送">
              <el-col :span="8" v-for="(item,index) in copylista" :key='index' class="copyli">
                {{item}}
              </el-col>
            </el-form-item>
          </el-row>
          <div class="button-action" v-if='!formDisabled'>
            <el-button type="primary" @click="submit" :loading="submitLoad1">提交</el-button>
            <el-button @click='cancel'>取消</el-button>
          </div>
        </el-form>
      </div>
      <!--视频-->
      <el-dialog ref="dialog" title="" :visible.sync="videoDialog" width="80%" center append-to-body
                 class="videoDialog">
        <div class="contant">
          <video autoplay width="100%" height="90%" controls :src="videoSrc"></video>
        </div>
      </el-dialog>
      <!--创建抄送组-->
      <el-dialog title="" :visible.sync="dialogVisible" width="80%" append-to-body class="copyGroup">
        <span>
            <h2 class="titleblue">创建抄送组</h2>
            <div class="contant">
                <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
                    <el-row :gutter="24">
                        <el-form-item label="群组名称" prop="name" class="group-name">
                            <el-input v-model="ruleForm.name"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row :gutter="24">
                        <el-form-item label="添加群成员">
                            <x-tree title="抄送组" ref="outlan" :groupData.sync="groupData"
                                    :treeList2.sync="treeList2"></x-tree>
                        </el-form-item>
                    </el-row>
                    <el-row :gutter="24">
                        <el-form-item class="footerbtn">
                            <el-button type="primary" @click="copysure" :loading="submitLoad2" class="sure">添加</el-button>
                            <el-button class="cancel" @click="copycancel">取消</el-button>
                        </el-form-item>
                    </el-row>
                </el-form>

            </div>
        </span>
      </el-dialog>
    </div>
  </el-dialog>
</template>

<script>
  import XTree from '@/components/common/XTree.vue'
  import taskObjectService from '@/services/TaskObjectService'
  import taskTypeService from '@/services/TaskTypeService'
  import msgGroupsService from '@/services/MsgGroupsService'
  import * as organizationService from '@/services/OrganizationService'
  import * as sysUserService from '@/services/SysUserService'
  import plansService from '@/services/PlansService'
  import taskService from '@/services/TaskService'
  import moment from 'moment'

  export default {
    // props: ['organization', 'taskType', 'taskObjectType', 'sysUser'],
    components: {
      'x-tree': XTree
    },
    data: function () {
      return {
        //  值班人员字段
        currentOrg: '',
        currentSubOrg: '',
        dutyId: '',
        subOrgList: [],
        subPeopleList: [],
        //  按钮loading
        submitLoad1: false,
        submitLoad2: false,
        onekeydialog: false,
        taskObject: [
          {taskObject: ''}
        ],
        zeroList: [],
        checkZero: false,
        checkOne: false,
        checkTwo: false,
        checkThree: false,
        checkFour: false,
        checkFive: false,
        checkSeven: false,
        checkCustom: false,
        title: '创建任务',
        type: 'add',
        formDisabled: false,
        readread: true,
        id: '',
        task: {
          createTime: '',
          sendTime: '',
          taskObject: '',
          summary: '',
          taskNo: '',
          name: '',
          type1: '',
          type2: '',
          type3: '',
          manageUnit: '',
          object1: '',
          object2: '',
          object3: '',
          object: '',
          objectOther: '',
          objectThree: '',
          outline: '',
          special: false,
          distribute: '',
          distributeSecond: '',
          grade: '',
          location: '',
          deadline: '',
          unit: [{
            person: '',
            carrier: '',
            vehicle: '',
            tool: ''
          }],
          typeradio: false,
          typeName: '',
          // url_file: [],
          fullname: '',
          url: [],
          pf_date: '',
          task_date: '',
          endTime: '',
          taskType: [{type1: '', type2: '', type3: ''}],
          taskTypeFlows: [{type1: '', type2: '', type3: '', taskType2: [], taskType3: []}],
          urlFile: [],
          finishTime: '',
        },//任务详情
        fileList: [],
        specialList: [],
        specialItem: [],
        approval: '0',
        objectInputShow: false,
        typeFirstOptions: [],
        typeSecondOptions: [],
        manageUnitOptions: [],
        objectOptions: [],
        distributeOptions: [],
        disSecondOptions: {},
        gradeOptions: [
          {
            id: 1,
            name: '一般'
          }, {
            id: 2,
            name: '紧急'
          }],
        bgImg: [],
        fileImg: [],
        bgImg1: [],
        fileImg1: [],
        rTask: false,
        personOptions: {},
        carrierOptions: {},
        toolOptions: {},
        vehicleOptions: {},
        value: '',
        specialArr: [],
        deptOptions: [],
        copylist: [],
        // copylistP: [],
        copylista: [],
        shipTypeThree: [],
        level: 0,
        lhpf: [
          {
            organiza: '',
            organiza2: '',
            organizas: [],
            enforceLaw: [{
              person: '',
              carrier: '',
              vehicle: '',
              tool: '',
              lawPeople: [],
              lawShip: [],
              lawCar: [],
              lawTool: [],
            }]
          }
        ],
        detailOrg: '',
        detailEn: '',
        detailUnit: [],
        lastorg: '',
        objectOptionSon: [],
        dows: [],
        laws: [],
        egs: [],
        dutys: [],
        leaderlist: [],
        checkLeader: false,
        checkedLeader: [],
        checkBroat: false,
        checkedBroat: [],
        checkDuty: false,
        checkedDuty: [],
        checkEg: false,
        checkedEg: [],
        checkLaw: false,
        checkedLaw: [],
        checkDow: false,
        checkedDow: [],
        isIndeterminate: true,
        xiangqing: true,
        form: {
          defectItem: [{defectitem: '', retention: ''}],
          numberdefects: '',
          retentionnumber: '',
          rectifynumber: '',
          othercases: '',
          remarks: '',
          finalResult: {
              measureCheck: [],
              textarea: ''
          },
          task_final: ''
        },
        punishment: [],
        business: '',
        uploadobj: {
          filename: '',
          mimeType: 'txt/doc/pdf',
          bus: 'task'
        },
        headers: {
          Authorization: 'Bearer ' + localStorage.getItem('token')
        },
        video: [],
        videoSrc: '',
        videoDialog: false,
        defaultProps: {
          children: 'children',
          label: 'label'
        },
        leaderlength: '',
        dowslength: '',
        lawslength: '',
        egslenght: '',
        dutyslength: '',
        mid: '',
        taskUrl: [],
        customize: [],
        checkCustomize: false,
        checkedCustomize: [],
        customizelength: '',
        dialogVisible: false,
        groupData: [],
        ruleForm: {
          name: ''
        },
        aa: [],
        cusChil: [],
        checkAll: false,
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7

          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date())
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', date)
            }
          }]
        },
        organization2: [], // 组织机构二级
        taskType2: [], // 任务类型二级
        organizaAll: [], // 全部组织机构
        Zero: [],
        One: [],
        Two: [],
        Three: [],
        Four: [],
        Five: [],
        Seven: [],
        Custom: [],
        copyArr: {
          zeroTree: [],
          oneTree: [],
          twoTree: [],
          threeTree: [],
          // fourTree: [],
          // fiveTree: [],
          // sevenTree: [],
          customTree: []
        },
        plans: [],
        detailId: null,
        createTime: null,
        treeList2: [],
        taskType: [], // 任务类型
        taskObjectType: [], // 任务对象类型
        organization: [], // 组织机构
        sysUser: [], // 全部组织机构人员
        isLoading: null // 全局loading
      }
    },
    computed: {
      copylistP() {
        let arr = [], custom = this.copyArr.customTree
        arr.push(...this.copyArr.zeroTree)
        arr.push(...this.copyArr.oneTree)
        arr.push(...this.copyArr.twoTree)
        arr.push(...this.copyArr.threeTree)
        // arr.push(...this.copyArr.fourTree)
        // arr.push(...this.copyArr.fiveTree)
        // arr.push(...this.copyArr.sevenTree)
        for (let a = 0; a < custom.length; a++) {
          for (let b = 0; b < arr.length; b++) {
            if (custom[a].label == arr[b].label) {
              custom.splice(a, 1)
            }
          }
        }
        arr.push(...this.copyArr.customTree)
        return arr
      }
    },
    // async mounted() {
    //
    // },
    async mounted() {
      this.onekeydialog = true
      this.isLoading = this.$loading({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
        })
      await this.getSelect()
      if (this.$route.params.type) {
        this.id = this.$route.params.id
        if (this.$route.params.type == 'edit') {
          this.type = 'edit'
          this.formDisabled = false
          this.title = '编辑任务'
          this.showDetail()
        } else if (this.$route.params.type == 'view') {
          this.type = 'view'
          this.formDisabled = true
          this.title = '查看任务'
          this.showDetail()
        }
      } else {
        this.type = 'add'
        this.formDisabled = false
        this.title = '创建任务'
          this.xiangqing = false
        this.task.fullname = this.$profile.fullname
      }
        if(this.$route.query.nameCn){
            this.task.name = this.$route.query.nameCn
        }
      await this.selectAll()
      await this.getSendTree()
      await this.getCustom()
    },
    methods: {
      async changeOrg (val) {
          this.currentSubOrg = ''
          this.dutyId = ''
          this.subOrgList = []
          this.subPeopleList = []
          let arr = await this.sysUser.filter(item => {
              if (item.organiza && item.organiza.id) {
                  return item.organiza.id == val
              }
          })
          await arr.sort((a, b) => {
              if (a.level < b.level) {
                  return 1
              } else {
                  return -1
              }
              return 0
          })
          this.subPeopleList = arr
          for (var i of this.organization) {
              if (i.id === val && i.sub) {
                  this.subOrgList = i.sub
                  break
              }
          }
      },
      async searchGroup (val) {
          this.dutyId = ''
          this.subPeopleList = []
          let arr = await this.sysUser.filter(item => {
              if (item.organiza && item.organiza.id) {
                  return item.organiza.id == val
              }
          })
          await arr.sort((a, b) => {
              if (a.level < b.level) {
                  return 1
              } else {
                  return -1
              }
              return 0
          })
          this.subPeopleList = arr
      },
      close1() {
        this.onekeydialog = false
        this.$router.push('/everyday-task')
      },
      async getSelect() {
          let orgQuery = ''
          // 局领导，海事处，执法大队默认查看本部门的人
          if (this.$profile.organiza.businessOrg === 0 || this.$profile.organiza.businessOrg === 3 || this.$profile.organiza.businessOrg === 4) {
              if (this.$profile.organiza.parentId !== null) {
                  orgQuery = 'id=_=' + this.$profile.organiza.parentId + ';parentId=_=' + this.$profile.organiza.parentId
              } else {
                  orgQuery = 'id=_=' + this.$profile.organiza.id + ';parentId=_=' + this.$profile.organiza.id
              }
          }
        await taskTypeService.search().then(res => {
          this.taskType = res
        })
        await taskObjectService.search().then(res => {
          this.taskObjectType = res
        })
        await organizationService.findAll(orgQuery).then(async res => {
          await res.data.sort((a, b) => {
            if (a.businessOrg < b.businessOrg) {
              return -1
            }
            if (a.businessOrg > b.businessOrg) {
              return 1
            }
            return 0
          })
          this.organization = res.data
          this.organizaAll = res.dataAll
        })
        await sysUserService.findAll().then(res => {
          this.sysUser = res.data
        })
      },
      addTaskObjectRow() {
        this.taskObject.push({taskObject: ''})
      },
      async selectAll() {
        let obj = {zero: [], one: [], two: [], three: [], four: [], five: [], seven: [], zero: []}
        this.organizaAll.forEach(async item => {
          switch (item.businessOrg) {
            case 0:
              if (item.parentId) {
                  if (item.name.indexOf('处领导') < 0) {
                      obj.three.push({
                          id: item.id,
                          label: item.name,
                          children: []
                      })
                  }
              } else {
                obj.zero.push({
                  id: item.id,
                  label: item.name,
                  children: []
                })
              }
              break
            case 1:
              obj.one.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 2:
              obj.two.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 3:
                if (item.name.indexOf('处领导') < 0) {
                    obj.three.push({
                        id: item.id,
                        label: item.name,
                        children: []
                    })
                }
              break
            case 4:
              obj.four.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 5:
              obj.five.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
            case 7:
              obj.seven.push({
                id: item.id,
                label: item.name,
                children: []
              })
              break
          }
        })
        for (let key in obj) {
          obj[key] = await obj[key].map(item => {
            let arr = this.sysUser.filter(ele => {
              if (ele.organiza) {
                return ele.organiza.id == item.id
              }
            })
            item.children = arr.sort((a, b) => {
                if (a.level < b.level) {
                    return 1
                } else {
                    return -1
                }
                return 0
            }).map(element => {
              return {id: element.id, label: element.fullname}
            })
            return item
          })
        }
        this.Zero = obj.zero
        this.One = obj.one
        this.Two = obj.two
        if (obj.three[0].id == 70) {
            let eightSea = obj.three[0]
            obj.three.splice(0, 1)
            obj.three.push(eightSea)
        }
        this.Three = obj.three
        this.Four = obj.four
        this.Five = obj.five
        this.Seven = obj.seven
        // await organizationService.findAll().then(async res => {
        //   await res.data.sort((a, b) => {
        //     if (a.businessOrg < b.businessOrg) {
        //       return -1
        //     }
        //     if (a.businessOrg > b.businessOrg) {
        //       return 1
        //     }
        //     return 0
        //   })
        //   this.organization = res.data
        // })
        await plansService.searchAll().then(res => {
          this.plans = res
        })
        // sysUserService.findAll().then(res => {
        //   this.sysUser = res.data
        //   this.getSendTree()
        // })
      },
      copysure() {
        if (this.ruleForm.name.length == 0) {
          this.$alert('请填写群组名称')
          return false
        }
        this.submitLoad2 = true
        let arr = []
        arr = this.treeList2.map(item => {
          return {userId: item.id, userName: item.label}
        })
        let obj = {
          groupName: this.ruleForm.name,
          msgGroupUsers: arr
        }
        msgGroupsService.create(obj).then(res => {
          if (res) {
            this.$message({
              type: 'success',
              message: '创建成功'
            })
            this.dialogVisible = false
            this.submitLoad2 = false
            this.getCustom()
          }
        })
      },
      async getSendTree() {
        let tree = []
        for (let item of this.organization) {
          let obj = {
            id: item.id,
            label: item.name,
            level: 1,
            businessOrg: item.businessOrg,
            children: []
          }
          if (item.sub) {
            for (let key of item.sub) {
              let arr = []
              arr = this.sysUser.filter(fil => {
                if (fil.organiza) {
                  return fil.organiza.id == key.id
                }
              }).sort((a, b) => {
                  if (a.level < b.level) {
                      return 1
                  } else {
                      return -1
                  }
                  return 0
              })
              arr = arr.map(ma => {
                return {id: ma.id, label: ma.fullname, pId: ma.organiza.id, pBusinessOrg: ma.organiza.businessOrg}
              })
              obj.children.push({
                id: key.id,
                label: key.name,
                businessOrg: key.businessOrg,
                pId: item.id,
                level: 2,
                children: arr
              })
            }
          }
          tree.push(obj)
        }
        this.groupData = tree
      },
      async getCustom() {
        msgGroupsService.search().then(res => {
          this.Custom = res.map(item => {
            let arr = []
            if (item.msgGroupUsers) {
              for (let key of item.msgGroupUsers) {
                arr.push({
                  id: key.userId,
                  label: key.userName
                })
              }
            }
            arr.sort((a, b) => {
              if (a.id < b.id) {
                return -1
              }
              if (a.id > b.id) {
                return 1
              }
              return 0
            })
            return {id: item.id, label: item.groupName, children: arr}
          })
          this.isLoading.close()
        })
      },
      showDetail() {
        let data = this.$route.params.data
        this.task.createTime = data['createTime'] ? moment(data['createTime']).format('YYYY-MM-DD HH:mm:ss') : ''
        for (let key in data) {
          if (key == 'id') {
            this.detailId = data[key]
          } else if (key == 'createTime' && data[key]) {
            this.createTime = data[key]
          } else if ((key == 'sendTime' || key == 'finishTime') && data[key]) {
            this.task[key] = moment(data[key]).format('YYYY-MM-DD HH:mm:ss')
          } else if (key == 'taskObject' && data[key]) {
            this.taskObject = data[key].split(',').map(item => {
              return {taskObject: item}
            })
          } else if ((key == 'object1' || key == 'object2' || key == 'object3') && data[key]) {
            if(key == 'object1'){
              this.task.object1 = data['object1']
              let obj = this.taskObjectType.find(fin => {
                return fin.id == data['object1']
              })
              if(obj && obj.subset){
                this.objectOptionSon = obj.subset
                if(data['object2']) this.task.object2 = data['object2']
                let obj2 = obj.subset.find(fin => {
                  return fin.id == data['object2']
                })
                if(obj2 && obj2.subset){
                  this.shipTypeThree = obj2.subset
                  if(data['object3']) this.task.object3 = data['object3']
                }
              }
            }
          } else if (key == 'urlFile' && data[key]) {
            this.task.urlFile = data[key].split(',')
            this.fileImg1 = data[key].split(',')
            this.fileList = data[key].split(',').map(item => {
              return {
                name: item.substring(item.lastIndexOf('task/') + 5, item.length),
                link: item
              }
            })
          } else if (key == 'organiza' && data[key]) {
            this.organization.forEach(item => {
              if (data[key].level == 1 || data[key].level == 0) {
                this.lhpf[0].organiza = data[key].id
              } else {
                if (item.id == data[key].parentId) {
                  this.lhpf[0].organizas = item.sub
                  this.lhpf[0].organiza = item.id
                }
                this.lhpf[0].organiza2 = data[key].id
              }
            })
          } else if (key == 'taskUsers' && data[key]) {
            // console.log(data[key], data['organiza'])
            data[key].forEach(async (item, index) => {
              if (index > 0) {
                this.lhpf[0].enforceLaw.push({
                  person: '',
                  carrier: '',
                  vehicle: '',
                  tool: '',
                  lawPeople: [],
                  lawShip: [],
                  lawCar: [],
                  lawTool: [],
                })
              }
              if (data['organiza']) {
                this.lhpf[0].enforceLaw[index].lawPeople = await this.sysUser.filter(ele => {
                  if (ele.organiza && ele.organiza.id == data['organiza'].id) {
                    return ele.organiza.id == data['organiza'].id
                  }
                }).sort((a, b) => {
                      if (a.level < b.level) {
                          return 1
                      } else {
                          return -1
                      }
                      return 0
                  })
                this.lhpf[0].enforceLaw[index].person = item.userId
              }
            })
          } else if (key == 'deadline' && data[key]) {
            this.task.deadline = moment(data[key]).format('YYYY-MM-DD HH:mm:ss')
          } else if (key == 'endTime' && data[key]) {
            this.task.endTime = moment(data[key]).format('YYYY-MM-DD HH:mm:ss')
          } else if (key == 'taskTypeFlows' && data[key]) {
            data[key].forEach((item, index) => {
              if (index > 0) {
                this.task.taskTypeFlows.push({
                  type1: '',
                  type2: '',
                  type3: '',
                  taskType2: [],
                  taskType3: [],
                })
              }
              this.taskType.forEach(ele => {
                if (ele.id == item.type1) {
                  this.task.taskTypeFlows[index].taskType2 = ele.subset ? ele.subset : []
                  this.task.taskTypeFlows[index].type1 = item.type1
                }
                if (ele.subset) {
                  ele.subset.forEach(sub => {
                    if (sub.id == item.type2) {
                      this.task.taskTypeFlows[index].taskType3 = sub.subset ? sub.subset : []
                      this.task.taskTypeFlows[index].type2 = item.type2
                    }
                    if (sub.subset) {
                      sub.subset.forEach(sss => {
                        if (sss.id == item.type3) {
                          this.task.taskTypeFlows[index].type3 = item.type3
                        }
                      })
                    }
                  })
                }
              })
            })
          } else if (key == 'special' && data[key]) {
            this.task.special = true
            // this.specialItem
            this.specialList = data[key].split(',').map(item => {
              return item * 1
            })
          } else if (key == 'createUserName' && data[key]) {
            this.task.fullname = data[key]
          } else if (key == 'defectItem' && data[key]) {
            this.form.defectItem = JSON.parse(data[key])
          } else if (key == 'finalResult' && data[key]) {
            this.form.finalResult = JSON.parse(data[key])
          } else if (data[key]) {
            this.task[key] = data[key]
              this.form[key] = data[key]
          }
        }
      },
      treeChange(ele) {
        this.$refs[ele].getCheckedNodes()
        this.copyArr[ele] = this.$refs[ele].getCheckedNodes().filter(item => {
          return !item.children
        })
      },
      zeroChange(a, b, c) {
      },
      nodeChange(ele, name) {
        if (this[`check${name}`]) {
          //全选
          this.$refs[ele].setCheckedNodes(this[name])
        } else {
          //取消选中
          this.$refs[ele].setCheckedKeys([])
        }
      },
      getCopy() {
        this.$axios.get(this.$config['copyTask'], {
          params: {
            skey: localStorage.getItem('auth')
          }
        }).then((res) => {
          var data = res.data.content
          if (data.userGroup) {
            var cusperson = []
            for (var x of data.userGroup) {
              var children = []
              if (x.person) {
                for (var child of x.person) {
                  children.push({
                    label: child.fullname,
                    id: '1-' + child.d_id
                  })
                  cusperson.push({
                    label: child.fullname,
                    id: '1-' + child.d_id
                  })

                }
              }
              this.customize.push({
                id: '0-' + x.d_id,
                label: x.group_name,
                children: children
              })
              this.customizelength = parseInt(this.customize.length + cusperson.length)
            }
          }
        })
      },
      async submit() {
        let type1, type2, typeName, isNull, taskTypeFlows = [], distUnit = [], org = []
        if (!this.task.name.trim()) {
          this.$alert('请输入任务名称')
          return false
        }
        if (this.task.typeradio == false) {
          type1 = this.task.taskTypeFlows
          type2 = this.task.taskTypeFlows
          typeName = ''
          await this.task.taskTypeFlows.forEach(item => {
            if (!item.type1) {
              isNull++
            } else {
              taskTypeFlows.push({
                type1: item.type1 ? item.type1 : '',
                type2: item.type2 ? item.type2 : '',
                type3: item.type3 ? item.type3 : ''
              })
            }
          })
          if (this.task.taskTypeFlows.length == 0 || isNull == this.task.taskTypeFlows.length) {
            this.$alert('请选择任务类型')
            return false
          }
        } else {
          typeName = this.task.typeName
          type1 = ''
          type2 = ''
          if (!this.task.typeName.trim()) {
            this.$alert('请输入自定义任务类型')
            return false
          }
        }
        if (!this.dutyId) {
            this.$alert('请选择值班人员')
            return false
        }
        if (!this.task.summary.trim()) {
          this.$alert('请输入任务概要')
          return false
        }
        if (!this.task.grade) {
          this.$alert('请选择任务等级')
          return false
        }
          this.submitLoad1 = true
        for (let item of this.lhpf) {
          let busorg = null, sysUsers = []
          if (item.organiza2) {
            this.organizaAll.forEach(ele => {
              if (item.organiza2 == ele.id) {
                busorg = ele.businessOrg
              }
            })
            item.enforceLaw.forEach(element => {
              if (element.person) {
                sysUsers.push({id: element.person})
              }
            })
            distUnit.push({id: item.organiza2, businessOrg: busorg, sysUsers: sysUsers ? sysUsers : null})
          } else if (item.organiza) {
            this.organizaAll.forEach(ele => {
              if (item.organiza == ele.id) {
                busorg = ele.businessOrg
              }
            })
            distUnit.push({id: item.organiza, businessOrg: busorg, sysUsers: null})
          }
        }
        // for (let item of distUnit) {
        //   if ((this.$profile.organiza.businessOrg == 3 || this.$profile.organiza.businessOrg == 4) && item.id != this.$profile.organiza.id) {
        //     this.$message({
        //       type: 'warning',
        //       message: '不可越级派发,只可选择同级派发'
        //     })
        //     return false
        //   }
        // }
        let taskObj = await this.taskObject.map(item => {
          return item.taskObject
        })
          if (!this.task.urlFile) {
              this.task.urlFile = []
          }
        let obj = {
          dutyId: this.dutyId, // 值班人员
          name: this.task.name,
          taskTypeFlows: taskTypeFlows,
          taskObject: taskObj.join(','),
          object1: this.task.object1,
          object2: this.task.object2,
          object3: this.task.object3,
          summary: this.task.summary,
          urlFile: this.task.urlFile.length ? this.task.urlFile.join(',') : '',
          fullname: this.title == '编辑任务' ? '' : this.$profile.fullname,
          // distUnit: null,
          taskUsers: [], // 执法人员list
          special: this.specialList.length > 0 ? this.specialList.join(',') : '', // 专项
          grade: this.task.grade,
          //organizas: distUnit.length > 0 ? distUnit : [{id: 44, businessOrg: 5}],
          location: this.task.location,
          deadline: moment(this.task.deadline)._d,
          taskSource: 1,
          userIds: this.copylistP ? this.copylistP.map(item => {
            return item.id
          }) : []
        }
        if (distUnit.length > 0) {
          obj.organizas = distUnit
        } else {
          if (this.$profile.organiza.businessOrg == 1) {
            obj.organizas = [{id: 44, businessOrg: 5}]
          }else{
            this.$alert('请选择部门派发')
              this.submitLoad1 = false
            return false
          }
        }
        //   return false
        // if (distUnit) {
        if (this.title == '编辑任务') {
          obj.id = this.detailId
          obj.createTime = this.createTime
          taskService.update(obj, 1).then(res => {
            if (res) {
              this.$emit('close')
              this.onekeydialog = false
              this.$message({
                type: 'success',
                message: '修改成功'
              })
              this.submitLoad1 = false
            } else {
                this.$message({
                    type: 'error',
                    message: '修改失败'
                })
                this.submitLoad1 = false
            }
          })
        } else {
          taskService.create(obj).then(res => {
            if (res) {
              this.$emit('close')
              this.onekeydialog = false
              this.$message({
                type: 'success',
                message: '创建成功'
              })
              this.submitLoad1 = false
            } else {
                this.$message({
                    type: 'error',
                    message: '创建失败'
                })
                this.submitLoad1 = false
            }
          })
        }

        // }
        // return false

      },
      cancel() {
        this.$emit('close')
        this.onekeydialog = false
        for (let key in this.copyArr) {
          this.$refs[key].setCheckedKeys([])
        }
        this.checkZero = false
        this.checkOne = false
        this.checkTwo = false
        this.checkThree = false
        this.checkFour = false
        this.checkFive = false
        this.checkSeven = false
        this.checkCustom = false
      },
      // 添加任务类型
      addTaskTypesRow(index) {
        this.task.taskTypeFlows.push({
          type1: '',
          type2: '',
          type3: '',
          taskType2: [],
          taskType3: []
        })
      },
      //添加执法单元行
      async addUnitRow(index) {
        let arr = []
        await this.lhpf[index].enforceLaw.forEach(item => {
          if (item.lawPeople) {
            arr = item.lawPeople
          }
        })
        this.lhpf[index].enforceLaw.push({
          person: '',
          carrier: '',
          vehicle: '',
          tool: '',
          lawPeople: arr,
          lawShip: [],
          lawCar: [],
          lawTool: []
        })
        // }
      },
      addPfdw() {
        this.lhpf.push({
          organiza: '',
          organiza2: '',
          organizas: [],
          enforceLaw: [{
            person: '',
            carrier: '',
            vehicle: '',
            tool: '',
            lawPeople: [],
            lawShip: [],
            lawCar: [],
            lawTool: []
          }]
        })
      },
      typeChange(event, index) {
        this.task.taskTypeFlows[index].type2 = ''
        this.task.taskTypeFlows[index].taskType2 = []
        let type = this.taskType.find(item => {
          return item.id == event
        })
        if (type.subset) {
          this.task.taskTypeFlows[index].taskType2 = type.subset
        }
        // for (var key of this.taskType) {
        //   if (key.d_id == this.task.typeFirst) {
        //     this.typeSecondOptions = key.son
        //   }
        // }
      }, typeChange(event, index) {
        this.task.taskTypeFlows[index].type2 = ''
        this.task.taskTypeFlows[index].taskType2 = []
        let type = this.taskType.find(item => {
          return item.id == event
        })
        if (type.subset) {
          this.task.taskTypeFlows[index].taskType2 = type.subset
        }
        // for (var key of this.taskType) {
        //   if (key.d_id == this.task.typeFirst) {
        //     this.typeSecondOptions = key.son
        //   }
        // }
      },
      typeChange2(event, index) {
        this.task.taskTypeFlows[index].type3 = ''
        this.task.taskTypeFlows[index].taskType3 = []
        let type = this.task.taskTypeFlows[index].taskType2.find(item => {
          return item.id == event
        })
        if (type.subset) {
          this.task.taskTypeFlows[index].taskType3 = type.subset
        }
        // for (var key of this.taskType) {
        //   if (key.d_id == this.task.typeFirst) {
        //     this.typeSecondOptions = key.son
        //   }
        // }
      },
      objectChange(val) {
        this.task.object2 = ''
        this.objectOptionSon = []
        this.task.object3 = ''
        this.shipTypeThree = []
        for (let key of this.taskObjectType) {
          if (val == key.id && key.subset) {
            this.objectOptionSon = key.subset
          }
        }
      },
      changeObjectType(val) {
        this.task.object3 = ''
        this.shipTypeThree = []
        for (let key of this.objectOptionSon) {
          if (val == key.id) {
            this.shipTypeThree = key.subset
          }
        }
      },
      typeEdit() {
        this.task.typeFirst = ''
        this.task.typeSecond = ''
      },
      getOptions() {
        taskTypeService.search().then((res) => {
          this.typeFirstOptions = res.filter((item) => {
            return item.level === 1
          })
        })
        taskObjectService.search().then((res) => {
          this.objectOptions = res.filter((item) => {
            return item.level === 1
          })
        })
      },
      manageChange1(val) {
        if (this.level == 0 || this.business == 1 || this.business == 2) {
          this.task.distributeSecond = ''
          this.$axios.get(this.$config['searchOSO'], {
            params: {
              skey: localStorage.getItem('auth'),
              dId: val
            }
          }).then((res) => {

            this.disSecondOptions[val] = res.data.content
          })
        }
        this.task.unit = []
        this.task.unit.push({
          'person': '',
          'carrier': '',
          'vehicle': '',
          'tool': ''
        })
        this.getUnitPeople(val)

      },
      manageChanges() {
        if (this.level == 0 || this.business == 1 || this.business == 2) {
          this.$axios.get(this.$config['searchOSO'], {
            params: {
              skey: localStorage.getItem('auth'),
              dId: this.mid
            }
          }).then((res) => {
            this.disSecondOptions[this.mid] = res.data.content

          })
        }
      },
      async manageChange(val, index) {
        this.lhpf[index].organiza2 = ''
        this.lhpf[index].organizas = []
        await this.lhpf[index].enforceLaw.map(item => {
          item.person = ''
          item.lawPeople = []
          return item
        })
        let organiza = this.organization.find(item => {
          return item.id == val
        })
        let arr = this.sysUser.filter(item => {
          if (item.organiza && item.organiza.id) {
            return item.organiza.id == val && item.level == 0
          }
        })
        await arr.sort((a, b) => {
            if (a.level < b.level) {
                return 1
            } else {
                return -1
            }
            return 0
        })
        await this.lhpf[index].enforceLaw.map(item => {
          item.person = ''
          item.lawPeople = arr
          return item
        })
        if (organiza.sub) {
          this.lhpf[index].organizas = organiza.sub
        }
      },
      async disChange(val, index) {
        let arr = await this.sysUser.filter(item => {
          if (item.organiza && item.organiza.id) {
            return item.organiza.id == val && item.level == 0
          }
        })
        await arr.sort((a, b) => {
            if (a.level < b.level) {
                return 1
            } else {
                return -1
            }
            return 0
        })
        await this.lhpf[index].enforceLaw.map(item => {
          item.person = ''
          item.lawPeople = arr
          return item
        })
      },
      disChange1(val) {
        this.task.unit = []

        this.task.unit.push({
          'person': '',
          'carrier': '',
          'vehicle': '',
          'tool': ''
        })
        this.getUnitPeople(val)
      },

      getUnitPeople(val, index, bz) {
        this.$axios.get(this.$config['disUser'], {
          params: {
            skey: localStorage.getItem('auth'),
            dId: val
          }
        }).then((res) => {
          this.personOptions[val] = res.data.content
        })
        this.$axios.get(this.$config['searchLawUnit'], {
          params: {
            skey: localStorage.getItem('auth'),
            orgId: val
          }
        }).then((res) => {
          var data = res.data.content
          this.vehicleOptions[val] = data.cars
          this.carrierOptions[val] = data.ships
          this.toolOptions[val] = data.tools
        }).then(res => {
          if (this.level == 0) {
            if (index && bz == '2') {
              this.lhpf[index].dept_id = ''
              this.$set(this.lhpf[index], 'dept_id', val)
            } else {
              this.lastorg = val
            }
          } else {
            if (index) {
              this.lhpf[index].org_id = ''
              this.$set(this.lhpf[index], 'org_id', val)
            } else {
              this.lastorg = val
            }
          }
        })
      },
      makeCopy() {
        this.copylistP = []
        this.copylist = this.checkedLeader.concat(this.checkedDow, this.checkedLaw, this.checkedDuty, this.checkedEg)
        var arr = this.leaderlist.concat(this.dows, this.laws, this.dutys, this.egs)
        //   for(var i of this.copylist){
        //       for(var j of arr){
        //           if(j.id==i){
        //               this.copylistP.push(j.name)
        //               break;
        //           }
        //       }
        //   }
        for (var i of this.copylist) {
          for (var j of arr) {
            if (j.id == i.id) {
              this.copylistP.push(j.label)
              break
            } else if (j.children) {
              for (var k of j.children) {
                if (k.id == i.id) {
                  this.copylistP.push(k.label)
                  break
                }
              }
            }
          }
        }

      },
      //全选
      leaderAll(val) {
        if (val) {
          this.$refs.treeLeader.setCheckedNodes(this.leaderlist)
          this.checkedLeader = this.$refs.treeLeader.getCheckedNodes()
        } else {
          this.$refs.treeLeader.setCheckedNodes([])
          this.checkedLeader = []
        }
        // var arr = []
        // for (var i of this.leaderlist) {
        //     arr.push(i.id)
        // }
        // this.checkedLeader = val ? arr : [];

        this.makeCopy()
      },
      leaderAllChange(value) {
        let checkedLeader = value.length
        this.checkLeader = checkedLeader === this.leaderlist.length
        this.makeCopy()
      },
      dowAll(val) {
        if (val) {
          this.$refs.treeDows.setCheckedNodes(this.dows)
          this.checkedDow = this.$refs.treeDows.getCheckedNodes()
        } else {
          this.$refs.treeDows.setCheckedNodes([])
          this.checkedDow = []
        }
        // var arr = []
        // for (var i of this.dows) {
        //     arr.push(i.id)
        // }
        // this.checkedDow = val ? arr : [];
        this.makeCopy()
      },
      dowAllChange(value) {
        let checkedDow = value.length
        this.checkDow = checkedDow === this.dows.length
        this.makeCopy()
      },
      lawAll(val) {
        // var arr = []
        // for (var i of this.laws) {
        //     arr.push(i.id)
        // }
        // this.checkedLaw = val ? arr : [];
        // this.makeCopy()
        if (val) {
          this.$refs.treelaws.setCheckedNodes(this.laws)
          this.checkedLaw = this.$refs.treelaws.getCheckedNodes()
        } else {
          this.$refs.treelaws.setCheckedNodes([])
          this.checkedLaw = []
        }
        this.makeCopy()
      },
      lawAllChange(value) {
        let checkedLaw = value.length
        this.checkLaw = checkedLaw === this.laws.length
        this.makeCopy()
      },
      dutyAll(val) {
        // var arr = []
        // for (var i of this.dutys) {
        //     arr.push(i.id)
        // }
        // this.checkedDuty = val ? arr : [];
        // this.makeCopy()

        if (val) {
          this.$refs.treeDutys.setCheckedNodes(this.dutys)
          this.checkedDuty = this.$refs.treeDutys.getCheckedNodes()
        } else {
          this.$refs.treeDutys.setCheckedNodes([])
          this.checkedDuty = []
        }
        this.makeCopy()
      },
      dutyAllChange(value) {
        let checkedDuty = value.length
        this.checkDuty = checkedDuty === this.dutys.length
        this.makeCopy()
      },
      egAll(val) {
        // var arr = []
        // for (var i of this.egs) {
        //     arr.push(i.id)
        // }
        // this.checkedEg = val ? arr : [];
        // this.makeCopy()
        if (val) {
          this.$refs.treeEgs.setCheckedNodes(this.egs)
          this.checkedEg = this.$refs.treeEgs.getCheckedNodes()
        } else {
          this.$refs.treeEgs.setCheckedNodes([])
          this.checkedEg = []
        }
        this.makeCopy()
      },
      egAllChange(value) {
        let checkedEg = value.length
        this.checkEg = checkedEg === this.egs.length
        this.makeCopy()
      },
      customizeAll(val) {
        if (val) {
          this.$refs.treeCustomize.setCheckedNodes(this.customize)
          this.checkedCustomize = this.$refs.treeCustomize.getCheckedNodes()
        } else {
          this.$refs.treeCustomize.setCheckedNodes([])
          this.checkedCustomize = []

        }
        this.copylistP = []

        this.cusChil = []
        for (var i of this.checkedCustomize) {
          if (!i.children) {
            this.cusChil.push(i)
          }
        }

        for (var i of this.cusChil) {
          for (var j of this.checkedCustomize) {
            if (j.id == i.id) {
              this.copylistP.push(j.label)
              this.copylistP = Array.from(new Set(this.copylistP))
              break
            } else if (j.children) {
              for (var k of j.children) {
                if (j.id == i.id) {
                  this.copylistP.push(j.label)
                  this.copylistP = Array.from(new Set(this.copylistP))
                  break
                }
              }
            }
          }
        }
        // this.makeCopy()
      },
      customizeAllChange(value) {
        let checkedCustomize = value.length
        this.checkCustomize = checkedCustomize === this.customize.length
        // this.makeCopy()
      },
      beforeupload(file) {
        var tpye = file.name.slice(file.name.lastIndexOf('.') + 1)
        if (tpye == 'jpeg' || tpye == 'jpg' || tpye == 'png') {
          this.uploadobj.mimeType = 'image/jpeg'
        } else if (tpye == 'doc' || tpye == 'docx') {
          this.uploadobj.mimeType = 'application/msword'
        } else if (tpye == 'pdf') {
          this.uploadobj.mimeType = 'application/pdf'
        } else if (tpye == 'txt') {
          this.uploadobj.mimeType = 'text/plain'
        } else if (tpye == 'xlsx' || tpye == 'xls') {
          this.uploadobj.mimeType = 'application/vnd.ms-excel'
        }
        this.uploadobj.filename = file.name
        return true
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 9 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
      },
      uploadSuccess(res) {
          if (!this.task.urlFile) {
              this.task.urlFile = []
          }
        this.task.urlFile.push(res.data.link)
      },
      uploadRemove: function (res) {
        if (this.task.urlFile.length > 0) {
          for (let i = 0; i < this.task.urlFile.length; i++) {
            if (this.task.urlFile[i] == res.response.data.link) {
              this.task.urlFile.splice(i, 1)
            }
          }
        }
      },
      videoPlay(id) {
        this.videoSrc = this.video[id]
        this.videoDialog = true
      },
      leaderChange(val, node) {
        this.checkedLeader = node.checkedNodes
        this.makeCopy()

      },
      dowsChange(val, node) {
        this.checkedDow = node.checkedNodes
        this.makeCopy()
      },
      lawsChange(val, node) {
        this.checkedLaw = node.checkedNodes
        this.makeCopy()
      },
      egsChange(val, node) {
        this.checkedEg = node.checkedNodes
        this.makeCopy()
      },
      dutyChange(val, node) {
        this.checkedDuty = node.checkedNodes
        this.makeCopy()
      },
      customizeChange(val, node) {
        // this.checkedCustomize = node.checkedNodes
        this.copylistP = []
        this.checkedCustomize = node.checkedNodes

        this.cusChil = []
        for (var i of this.checkedCustomize) {
          if (!i.children) {
            this.cusChil.push(i)
          }
        }

        for (var i of this.cusChil) {
          for (var j of this.checkedCustomize) {
            if (j.id == i.id) {
              this.copylistP.push(j.label)
              this.copylistP = Array.from(new Set(this.copylistP))
              break
            } else if (j.children) {
              for (var k of j.children) {
                if (j.id == i.id) {
                  this.copylistP.push(j.label)
                  this.copylistP = Array.from(new Set(this.copylistP))
                  break
                }
              }
            }
          }
        }
      },
      //自定义抄送
      cusClick() {
        this.dialogVisible = true
      },
      //自定义群组
      groupData1() {
        var arr = []
        this.$axios.get('OrganizationSelectAllUserByOrg', {
          params: {
            'skey': localStorage.getItem('auth')
          }

        }).then((res) => {
          arr.push({
            d_id: 1,
            name: '全部',
            users: res.data.content.userAll
          })
        }).then(() => {
          this.$axios.get('OrganizationSelectAllUserByOrg', {
            params: {
              'skey': localStorage.getItem('auth')
            }

          }).then((res) => {
            this.groupData = arr.concat(res.data.content.userOrg)
          })
        })
      },
      copycancel() {
        this.dialogVisible = false
      },
      clearCopy() {
        this.ruleForm.name = ''
        this.ruleForm.idStr = []
        this.$refs.treeCustomize.setCheckedKeys([])

      },
    }
  }
</script>

<style lang="scss">
  .copylist {
    margin-bottom: 10px;
  }

  .refine_dtcreate {
    .contant {
      padding-bottom: 20px;

      .el-col {
        label {
          //width:100px;
        }

        .type-wrap {
          .w98 {
            width: 98%;
          }
        }

        .select-width-150 {
          width: 150px;
          float: left;
          margin-right: 10px;
        }

        .select-width-300 {
          width: 300px;
          float: left;
          margin-right: 10px;
        }

        .unit-wrap {
          margin-bottom: 10px;

          .w33 {
            width: 22.3%;
            float: left;
            margin: 0 1%;
          }

          .w33:first-child {
            margin-left: 0;
          }

          i {
            float: left;
            line-height: 40px;
            font-size: 20px;
            cursor: pointer;
          }
        }

        .blue-button {
          width: 126px;
          margin-left: 20px;
        }

        .special-cont .el-checkbox-group {
          font-size: 0;
          box-sizing: border-box;
          height: 150px;
          overflow-y: scroll;
          border: 1px solid #ccc;
          padding: 0px 20px;
          width: 480px;

          label {

            margin-left: 0;
            float: left;
            height: 30px;
            margin-right: 30px;
            min-width: 40%;

          }

        }

        .annex-width > .annex-div > img {
          width: 62px;
          height: 64px;
          border-radius: 2px;
          float: left;
          margin-right: 10px;
          cursor: pointer;
          position: absolute;
          margin-bottom: 20px;
        }

        .annex-width {
          padding: 0 !important;
          background-color: transparent !important;
          border: 0px !important;
        }

        .annex-div {
          margin-right: 10px;
          width: 62px;
          height: 64px;
          display: block;
          float: left;
          position: relative;
        }

        .file-div {
          width: auto;
          height: auto;
          padding: 0px;
          /*color: #333;*/
          margin-left: 0px;
          margin-right: 10px;

        }


      }

      .button-action {
        text-align: center;

        .el-button {
          float: none;
          display: inline-block;
          width: 110px;
          margin: 20px 15px;
        }
      }

      .blue-button {
        width: 126px;
        margin-left: 20px;
      }

      .el-upload__tip {
        width: 300px;
        height: 40px;
        border-radius: 2px;
        border: solid 1px #dddddd;
        float: left;
        margin-top: 0;
        padding: 0 15px;
        font-size: 14px;
        color: #b9b9b9;
        text-align: left;
        box-sizing: border-box
      }

      .el-upload--text {
        float: right;
        width: 58px;
        height: 40px;
        border: none;
        border-radius: 2px;
        margin-left: 5px;
      }

      .el-upload--text button {
        background-color: #0062cd;
        border-radius: 2px;
        border: none;
        padding: 0;
        width: 58px;
        height: 40px;
        text-align: center;
        margin-left: 0px !important;
      }

      .button-action {
        padding-bottom: 30px;
      }

      ._select-width-200 {
        margin-top: 10px;
      }

      .punish {
        width: auto !important;
        margin-right: 10px;
        float: left;
      }

      .checkgroup {
        .allchck {
          margin-left: 12px !important;
        }

        .el-checkbox {
          float: left;
          margin-left: 0px;
        }

        .el-checkbox__input {
          display: inline-block;
        }

        .el-checkbox__label {
          display: inline-block;
          max-width: 90%;
          vertical-align: -4px;
          overflow: hidden;
          text-overflow: ellipsis;
          padding-left: 5px;
        }

        .el-form-item__content {
          width: 90%;
          box-sizing: border-box;
        }


      }

      .groupli {
        border: 1px solid #ddd;
        height: 400px;
        // margin-right:10px;
        padding: 0px 4px;

        P {
          font-size: 14px;
          line-height: 30px;
        }

        li {
          line-height: 30px;
          border-bottom: 1px solid #ddd;
        }

        .el-tree-node__content > .el-tree-node__expand-icon {
          padding: 0px;
        }

        .el-tree-node {
          width: 100%;
          float: left;
          display: inline-table;
        }

      }

      .copylist {
        overflow-y: auto
      }
    }

    .csdiv {

      .el-form-item {
        width: 100%
      }

      .el-form-item__content {
        width: 80%;
        border: 1px solid #ddd;
        padding: 10px;
        box-sizing: border-box;
      }
    }

    .copybtn {
      width: 50px;
      height: 20px;
      background-color: #0062cd;
      border-radius: 4px;
      font-size: 12px;
      color: #ffffff;
      text-align: center;
      line-height: 20px;
      cursor: pointer;
      margin-top: 10px;
      margin-right: 2px;
    }

    .el-tree__empty-block {
      margin-top: 30px;
    }

  }

  .copyGroup {
    .group-name input {
      width: 310px;
    }

    .tree .el-tree {
      height: 254px;
    }
  }

  @media only screen and (min-width: 1200px) and (max-width: 1365px) {
    .height-300 {
      width: 96%
    }
  }

  @media only screen and (min-width: 1366px) and (max-width: 1366px) {
    .height-300 {
      width: 98%
    }
  }

  @media only screen and (min-width: 1367px) and (max-width: 1919px) {
    .height-300 {
      width: 86%
    }
  }

  @media only screen and (min-width: 1920px) {
    .height-300 {
      width: 79%
    }
  }
</style>
